package org.yefei.homeworkday10;

public class QuickSort {
	// 快速排序
	public static void main(String[] args) {

		int[] list = { 99, 101, 999, 2, 7, 15, 90, 89, 22, 66, 80 };
		quickS(list, 0, list.length - 1);
		for (int i = 0; i < list.length; i++) {
			System.out.print(list[i] + "  ");
		}

	}

	public static void quickS(int[] list, int left, int right) {

		if (left < right) {
			int temp = division(list, left, right);
			quickS(list, left, temp - 1);
			quickS(list, temp + 1, right);
		}

	}

	public static int division(int[] list, int left, int right) {
		int temp = list[left];
		while (left < right) {
			while (left < right && list[right] >= temp) {
				right--;
			}
			list[left] = list[right];
			while (left < right && list[left] <= temp) {
				left++;
			}
			list[right] = list[left];
		}
		list[left] = temp;
		return left;
	}

}
